package nix.mall.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import nix.mall.common.pojo.EasyUIDataGridResult;
import nix.mall.common.pojo.NixMallResult;
import nix.mall.content.service.ContentService;
import nix.mall.pojo.Content;

/**
 * 内容管理Controller
 */
@Controller
public class ContentController {

	@Autowired
	private ContentService contentService;
	
	@RequestMapping(value = "/content/save", method = RequestMethod.POST)
	@ResponseBody
	public NixMallResult addContentCategory(Content content) {
		NixMallResult result = contentService.addContent(content);
		return result;
	}
	
	@RequestMapping("/content/query/list")
	@ResponseBody
	public EasyUIDataGridResult getContentListByCatId(Long categoryId, Integer page, Integer rows) {
		EasyUIDataGridResult result = contentService.getContentListByCatId(categoryId, page, rows);
		return result;
	}
	
	@RequestMapping("/content/{contentId}")
	@ResponseBody
	public NixMallResult getItemById(@PathVariable Long contentId) {
		Content content = contentService.getContentById(contentId);		
		return NixMallResult.ok(content);
	}
	
	@RequestMapping(value = "/content/edit", method = RequestMethod.POST)
	@ResponseBody
	public NixMallResult editContent(Content content) {
		NixMallResult result = contentService.editContent(content);
		return result;
	}
	
	@RequestMapping(value = "/content/delete", method = RequestMethod.POST)
	@ResponseBody
	public NixMallResult delContentByIds(String ids) {
		NixMallResult result = contentService.delContentByIds(ids);
		return result;
	}	
}
